/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * guiPlaylistCreate.java
 *
 * Created on 11/06/2011, 13:30:05
 */

package guiPlaylisted.view;

import dataPlaylisted.Playlist;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;

/**
 *
 * @author Administrador
 */
public class guiPlaylistCreate extends javax.swing.JDialog {

    private PlaylistView m_playlistView;

    private String m_style;
    private String m_cammelot;

    /** Creates new form guiPlaylistCreate */
    public guiPlaylistCreate(java.awt.Frame parent, boolean modal) throws FileNotFoundException, IOException, ClassNotFoundException {
        super(parent, modal);
        initComponents();

        m_playlistView = PlaylistView.getInstance();

        this.setComboBoxes();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jComboStyle = new javax.swing.JComboBox();
        jBtStyle = new javax.swing.JButton();
        jBtCancel = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jComboCammelot = new javax.swing.JComboBox();
        jBtCammelot = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jLabel1.setName("jLabel1"); // NOI18N

        jComboStyle.setName("jComboStyle"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(guiPlaylisted.PlaylistedApp.class).getContext().getActionMap(guiPlaylistCreate.class, this);
        jBtStyle.setAction(actionMap.get("onPlaylistStyle")); // NOI18N
        jBtStyle.setName("jBtStyle"); // NOI18N

        jBtCancel.setAction(actionMap.get("onCancel")); // NOI18N
        jBtCancel.setName("jBtCancel"); // NOI18N

        jLabel5.setName("jLabel5"); // NOI18N

        jComboCammelot.setName("jComboCammelot"); // NOI18N

        jBtCammelot.setAction(actionMap.get("onPlaylistCammelot")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(guiPlaylisted.PlaylistedApp.class).getContext().getResourceMap(guiPlaylistCreate.class);
        jBtCammelot.setText(resourceMap.getString("jBtCammelot.text")); // NOI18N
        jBtCammelot.setName("jBtCammelot"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(307, Short.MAX_VALUE)
                .addComponent(jBtCancel)
                .addGap(29, 29, 29))
            .addGroup(layout.createSequentialGroup()
                .addGap(147, 147, 147)
                .addComponent(jLabel5)
                .addContainerGap(224, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(56, 56, 56)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jComboCammelot, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jComboStyle, javax.swing.GroupLayout.Alignment.LEADING, 0, 142, Short.MAX_VALUE))
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jBtCammelot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jBtStyle, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE))
                .addContainerGap(47, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addGap(47, 47, 47)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jBtStyle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jComboStyle)
                        .addComponent(jLabel1)))
                .addGap(37, 37, 37)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboCammelot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtCammelot))
                .addGap(102, 102, 102)
                .addComponent(jBtCancel)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    guiPlaylistCreate dialog = new guiPlaylistCreate(new javax.swing.JFrame(), true);
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                        public void windowClosing(java.awt.event.WindowEvent e) {
                            System.exit(0);
                        }
                    });
                    dialog.setVisible(true);
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(guiPlaylistCreate.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(guiPlaylistCreate.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(guiPlaylistCreate.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    private void setComboBoxes(){
        int size_style = m_playlistView.getMusicView().getStyles().size();
        for (int i=0; i < size_style; i++){
            jComboStyle.addItem(m_playlistView.getMusicView().getStyles().get(i));
        }

        int size_cammelot = m_playlistView.getMusicView().getWhell().size();
        for (int i=0; i < size_cammelot; i++){
            jComboCammelot.addItem(m_playlistView.getMusicView().getWhell().get(i));
        }
    }

    @Action
    public void onPlaylistStyle() throws FileNotFoundException, IOException, ClassNotFoundException {
        m_style = (String) jComboStyle.getSelectedItem();
        Playlist _playlist = m_playlistView.makePlaylistStyle(m_style);
        m_playlistView.runPlaylistCreateView(_playlist);
        this.dispose();
    }

    @Action
    public void onPlaylistCammelot() throws FileNotFoundException, IOException, ClassNotFoundException {
        m_cammelot = (String) jComboCammelot.getSelectedItem();
        Playlist _playlist = m_playlistView.makePlaylistCammelot(m_cammelot);
        m_playlistView.runPlaylistCreateView(_playlist);
        this.dispose();
    }

    @Action
    public void onCancel() {
        this.dispose();
    }



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtCammelot;
    private javax.swing.JButton jBtCancel;
    private javax.swing.JButton jBtStyle;
    private javax.swing.JComboBox jComboCammelot;
    private javax.swing.JComboBox jComboStyle;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel5;
    // End of variables declaration//GEN-END:variables

}
